package com.gxa.customer.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxa.common.commons.R;
import com.gxa.common.params.HousePaymentDetailAddParam;
import com.gxa.common.params.QueryHousePaymentDetailParam;
import com.gxa.common.params.UpdateHousePaymentDetailParam;
import com.gxa.common.pojo.HousePaymentDetail;
import com.gxa.common.utils.RUtils;
import com.gxa.customer.mapper.HousePaymentDetailMapper;
import com.gxa.customer.service.HousePaymentDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HousePaymentDetailServiceImpl implements HousePaymentDetailService {
    @Autowired
    private HousePaymentDetailMapper housePaymentDetailMapper;
    @Override
    public R addHousePaymentDetail(HousePaymentDetailAddParam param) {
        //①用户账户扣钱API
        //todo
        //②平台账户增加钱API
        //todo
        //③新增一条房款支付明细记录
        HousePaymentDetail housePaymentDetail = new HousePaymentDetail();
        BeanUtils.copyProperties(param,housePaymentDetail);
        housePaymentDetailMapper.insert(housePaymentDetail);
        return RUtils.success();
    }

    @Override
    public R queryHousePaymentDetail(QueryHousePaymentDetailParam param) {
        QueryWrapper<HousePaymentDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("nation_id",param.getNationId()).eq("customer_id",param.getCustomerId());
        List<HousePaymentDetail> list = housePaymentDetailMapper.selectList(wrapper);
        return RUtils.success(list);
    }

    @Override
    public R updateHousePaymentDetail(UpdateHousePaymentDetailParam param) {
        HousePaymentDetail housePaymentDetail = new HousePaymentDetail();
        BeanUtils.copyProperties(param,housePaymentDetail);
        housePaymentDetailMapper.updateById(housePaymentDetail);
        return RUtils.success();
    }

    @Override
    public R delHousePaymentDetail(Long id) {
        housePaymentDetailMapper.deleteById(id);
        return RUtils.success();
    }
}
